<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-10-25
 * Time: 下午4:43
 * To change this template use File | Settings | File Templates.
 */
class SUBMIT{
    private $db;

    function __construct($db){
        $this->db=$db;
    }
    function checkisexsit($wx_num){//审查该微信关注是否已经提交过
        $sql="select wx_default_num from weixin where 1=1  and (wx_default_num='$wx_num' or wx_num='$wx_num')";
        $result=$this->db->query_all($sql);
        if(empty($result)){
            return false;
        }else{
            return true;
        }
    }
    function request_submit($data){//提交
        $set_sql=$this->_sql($data);
        $wx_d_num_isexsit=$this->checkisexsit($data["wx_default_num"]);
        $wx_num_isexsit=$this->checkisexsit($data["wx_num"]);
        if($wx_d_num_isexsit){
            return -2;
        }elseif($wx_num_isexsit){
            return -1;
        }
        $sql="insert into weixin set $set_sql,add_time=".time().",lastmodify_time=".time()."";
        $result=$this->db->query($sql);
        if($result){
            return 1;
        }else{
            return 0;
        }
    }
    private function _sql($data){
        $sql='';

        if(empty($data)){
            return false;
        }else{
            foreach($data as $key=>$value){
                $sql.=",".$key."='".$value."'";
            }
            return trim($sql,",");
        }

    }
}